import { Method } from '../method'
import service from '../service'
import { downloadFile } from '@/lib/utils'

export default {
  invoice(
    invoiceType: number,
    payOrderId: number,
    payerEmail: string,
    taxpayerIdentityNumber: string,
    mobileCode: string
  ) {
    return service({
      url: `/seal/rest/payOrder/invoice`,
      method: Method.POST,
      body: {
        invoiceType,
        payOrderId,
        payerEmail,
        taxpayerIdentityNumber,
        mobileCode,
      },
    })
  },
  queryPayOrderInfo(payOrderId: number) {
    return service({
      url: `/seal/rest/payOrder/queryPayOrderInfo`,
      method: Method.POST,
      body: {
        payOrderId,
      },
    })
  },
  queryByOrderId(payOrderId: number) {
    return service({
      url: `/seal/rest/payOrder/logistics/queryByOrderId`,
      method: Method.POST,
      body: {
        payOrderId,
      },
    })
  },
  queryOrderList(data: any) {
    return service({
      url: `/seal/rest/payOrder/queryOrderList`,
      method: Method.POST,
      body: data,
    })
  },
  queryAllStatusCount() {
    return service({
      url: `/seal/rest/payOrder/queryAllStatusCount`,
      method: Method.POST,
      body: {},
    })
  },
  queryPayOrderCreatedInfo(data: any) {
    return service({
      url: `/seal/rest/payOrder/queryPayOrderCreatedInfo`,
      method: Method.POST,
      body: data,
    })
  },
  queryPayOrderStatus(data: any) {
    return service({
      url: `/seal/rest/payOrder/queryPayOrderStatus`,
      method: Method.POST,
      body: data,
    })
  },
  confirmPayOrder(data: any) {
    return service({
      url: `/seal/rest/payOrder/confirmPayOrder`,
      method: Method.POST,
      body: data,
    })
  },
  invoiceDownLoad(data: any) {
    // 下载发票
    const url = `${window.location.origin}/seal/rest/payOrder/invoiceDownLoad?payOrderId=${data}`
    downloadFile(url, '发票')
  },
  invoiceDirect(payOrderId: number) {
    // 申请开票
    return service({
      url: `/seal/rest/payOrder/invoiceDirect`,
      method: Method.POST,
      body: {
        payOrderId,
      },
    })
  },
  cancelPayOrder(payOrderId: number) {
    return service({
      url: `/seal/rest/payOrder/cancelPayOrder`,
      method: Method.POST,
      body: {
        payOrderId,
      },
    })
  },
  queryInvoiceProduceStatus(payOrderId: number) {
    return service({
      url: `/seal/rest/payOrder/queryInvoiceProduceStatus`,
      method: Method.POST,
      body: {
        payOrderId,
      },
    })
  },
}
